#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
#   GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
#   Author :  Shawn.Tan
#   Date : 2025.10.28
#
#   History : Initial Version 2025.10.28
#
#
from base.ChoicesModifier import ChoicesModifier


class AddressReuseEnabledChoicesModifier(ChoicesModifier):
    def apply(self, **kwargs):
        reuse_mod_dict = {"No reuse": 0, "Reuse": 100}
        self.modifyOperandChoices("Read after read address reuse", reuse_mod_dict)
        self.modifyOperandChoices("Read after write address reuse", reuse_mod_dict)
        self.modifyOperandChoices("Write after read address reuse", reuse_mod_dict)
        self.modifyOperandChoices("Write after write address reuse", reuse_mod_dict)
        self.commitSet()


class AlignedDataOnlyChoicesModifier(ChoicesModifier):
    def apply(self, **kwargs):
        data_align_mod_dict = {
            "Aligned": 100,
            "Unaligned": 0,
            "Whole data aligned": 0,
        }
        self.modifyOperandChoices("Data alignment", data_align_mod_dict)
        self.commitSet()


class UnalignedDataOnlyChoicesModifier(ChoicesModifier):
    def apply(self, **kwargs):
        data_align_mod_dict = {
            "Aligned": 0,
            "Unaligned": 100,
            "Whole data aligned": 0,
        }
        self.modifyOperandChoices("Data alignment", data_align_mod_dict)
        self.commitSet()


class DataProcessingAddressResultChoicesModifier(ChoicesModifier):
    def apply(self, **kwargs):
        data_proc_result_mod_dict = {"Load store address": 100, "Random": 0}
        self.modifyOperandChoices("Data processing result", data_proc_result_mod_dict)
        self.commitSet()


#  NearBranchOnlyChoicesModifier alters the branch choices to always select
#  near branches.
class NearBranchOnlyChoicesModifier(ChoicesModifier):
    def apply(self, **kwargs):
        near_branch_mod_dict = {"Near branch": 100, "Long branch": 0}
        self.modifyOperandChoices("Branch type choice", near_branch_mod_dict)
        self.commitSet()


class NoSpXzrChoicesModifier(ChoicesModifier):
    def apply(self, **kwargs):
        gprs_or_sp_mod_dict = {"SP": 0}
        self.modifyOperandChoices("64-bit GPRs or SP", gprs_or_sp_mod_dict)
        gprs_mod_dict = {"XZR": 0}
        self.modifyOperandChoices("64-bit GPRs", gprs_mod_dict)
        self.commitSet()
